package com.erb.service.cgs.impl;

import com.erb.entity.*;
import com.erb.mapper.SmloadMapper;
import com.erb.service.cgs.SmloadService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class SmloadServiceimpl implements SmloadService {
	@Resource
	private SmloadMapper smloadMapper;

	@Override
	public Apply Selectstate(int uid, String loantype, int applyid) {
		Apply apply = smloadMapper.SelectState(uid, loantype, applyid);
		return apply;
	}

	@Override
	public List<Apply> selectapply(int uid, String applyid) {
		List<Apply> selectapply = smloadMapper.selectapply(uid, applyid);
		return selectapply;
	}

	@Override
	public void updusermoney(int id, double money) {
		smloadMapper.updusermoney(id,money);
	}

	@Override
	public void AddSmloan(Apply apply) {
		smloadMapper.AddSmloan(apply);
	}

	@Override
	public List<Loan> selectloan(int uid) {
		List<Loan> selectloan = smloadMapper.selectloan(uid);
		return selectloan;
	}

	@Override
	public List<Loan> selectpayloan(int uid, int agree) {
		List<Loan> selectpayloan = smloadMapper.selectpayloan(uid, agree);
		return selectpayloan;
	}



	@Override
	public Loan payloan(int lid) {
		Loan payloan = smloadMapper.payloan(lid);
		return payloan;
	}

	@Override
	public List<Loan> allloan() {
		List<Loan> allloan = smloadMapper.allloan();
		return allloan;
	}

	@Override
	public int addpayloan(int payint, Payloan payloan) {
		int addpayloan = smloadMapper.addpayloan(payloan, payint);
		return addpayloan;
	}

	@Override
	public Loan hetongloan(int lid, String loantype) {
		Loan hetongloan = smloadMapper.hetongloan(lid, loantype);
		return hetongloan;
	}

	@Override
	public Payloan loaning(int lid) {
		Payloan loaning = smloadMapper.loaning(lid);
		return loaning;
	}


	@Override
	public int paydate(int lid) {
		int paydate = smloadMapper.paydate(lid);
		return paydate;
	}

	@Override
	public List<Payloan> paylist(int lid) {
		List<Payloan> paylist = smloadMapper.paylist(lid);
		return paylist;
	}

	@Override
	public List<Payloan> nopaylist(int lid, int paystate) {
		List<Payloan> nopaylist = smloadMapper.nopaylist(lid, paystate);
		return nopaylist;
	}

	@Override
	public int updatepay(Payloan payloan) {
		int updatepay = smloadMapper.updatepay(payloan);
		return updatepay;
	}

	@Override
	public int updatepayall(Payloan payloan) {
		int updatepayall = smloadMapper.updatepayall(payloan);
		return updatepayall;
	}

	@Override
	public int updateloan(double repayment, int lid) {
		int updateloan = smloadMapper.updateloan(repayment, lid);
		return updateloan;
	}

	@Override
	public List<Apply> applylist() {
		return smloadMapper.applylist();
	}

	@Override
	public Apply seluid(int id) {
		return smloadMapper.seluid(id);
	}

	@Override
	public List<Carimf> carlists(int id) {
		return smloadMapper.carlists(id);
	}

	@Override
	public List<Houseimf> Houselist(int id) {
		return smloadMapper.Houselist(id);
	}

	@Override
	public List<Publicimf> publiclist(int id) {
		return smloadMapper.publiclist(id);
	}

	@Override
	public List<Insuranceimf> insurancelist(int id) {
		return smloadMapper.insurancelist(id);
	}

	@Override
	public void updApply(int state, int id) {
		smloadMapper.updApply(state, id);
	}

	@Override
	public int selProcount() {
		return smloadMapper.selProcount();
	}

	@Override
	public List<Apply> selApplyPage(Pager page) {
		System.out.println("分页尝试 1+ " + (page.currPage - 1) * page.pageSize + "分页参数2+ " + page.getPageSize());
		return smloadMapper.selApplyPage((page.currPage - 1) * page.pageSize, page.pageSize);
	}

	@Override
	public void addloansubmit(Loan loan) {
		smloadMapper.addloansubmit(loan);
	}

	@Override
	public Loan loanState(int uid, String loantype, int applyid) {
		Loan loanstate = smloadMapper.loanstate(uid, loantype, applyid);
		return loanstate;
	}

	@Override
	public void addpubliceimf(Publicimf publicimf) {
		smloadMapper.addpubliceimf(publicimf);
	}

	@Override
	public void addcarimf(Carimf carimf) {
		smloadMapper.addcarimf(carimf);
	}


	@Override
	public List<Map> selectcarimf(int uid) {
		List<Map> selectloandata = smloadMapper.selectcarimf(uid);
		return selectloandata;
	}

	@Override
	public void addhouseimf(Houseimf houseimf) {
		smloadMapper.addhouseimf(houseimf);
	}

	@Override
	public List<Map> selecthouseimf(int uid) {
		List<Map> selecthouseimf = smloadMapper.selecthouseimf(uid);
		return selecthouseimf;
	}

	@Override
	public String proimg(MultipartFile file) {
		// 把文件保存到upload目录下
		// 保存文件，这个文件名有的时候文件名可能会重复，你保存多了会把原来的图片给覆盖掉，这就不太合适了。
		// 所以为每个文件生成一个新的文件名
		String picName = UUID.randomUUID().toString();
		// 截取文件的扩展名(如.jpg)
		String oriName = file.getOriginalFilename();
		System.out.println("--上传文件名-->>" + oriName);
		String extName = oriName.substring(oriName.lastIndexOf("."));

//        String path = request.getSession().getServletContext().getRealPath("\\");  //获取项目路径
		String dirName = "C:/erb/img/";
		//创建文件夹
		File dirFile = new File(dirName);
		if (!dirFile.exists()) {
			dirFile.mkdirs();
		}
		//新文件名
		String newFileName = picName + extName;
		File targetFile = new File(dirName, newFileName);
		// 保存文件
		try {
			file.transferTo(targetFile);
		} catch (IOException e) {
			e.printStackTrace();
		}
		/* 把文件名保存到数据库 */
		System.out.println("本地路径---->>" + (dirName + newFileName));
		String jsonStr = "{\"code\" : 0 , \"relativePath\" : \"" + (dirName + newFileName) + "\"}";
		String pathnama = dirName + newFileName;
		System.out.println(pathnama);
		String substring = pathnama.substring(pathnama.lastIndexOf("/"));
		System.out.println(substring);
		return substring;
	}

	@Override
	public List<Map> carisnull(String caridcard) {
		List<Map> carisnull = smloadMapper.carisnull(caridcard);
		return carisnull;
	}

	@Override
	public List<Map> houseisnull(String housedata) {
		List<Map> houseisnull = smloadMapper.houseisnull(housedata);
		return houseisnull;
	}

	@Override
	public Publicimf selectpublic(int uid) {
		Publicimf selectpublic = smloadMapper.selectpublic(uid);
		return selectpublic;
	}

	@Override
	public void addinsuranceimf(Insuranceimf insuranceimf) {
		smloadMapper.addinsuranceimf(insuranceimf);
	}

	@Override
	public Insuranceimf selectinsuranceimf(int uid) {
		Insuranceimf selectinsuranceimf = smloadMapper.selectinsuranceimf(uid);
		return selectinsuranceimf;
	}

	@Override
	public List<Map> selectcarimf_user(int uid, int carowner) {
		List<Map> maps = smloadMapper.selectcarimf_user(uid, carowner);
		return maps;
	}

	@Override
	public void updatecarimf_user(int caridcard, int carapplyid) {
		smloadMapper.updatecarimf_user(caridcard, carapplyid);
	}

	@Override
	public void updatehouseimf_user(int houseid, int houseapplyid) {
		smloadMapper.updatehouseimf_user(houseid, houseapplyid);
	}

	@Override
	public List<Map> diyacarimf(int uid, int carapplyid, int carowner) {
		List<Map> diyacarimf = smloadMapper.diyacarimf(uid, carapplyid, carowner);
		return diyacarimf;
	}

	@Override
	public List<Map> diyahouserimf(int uid, int houseapplyid, int houseowner) {
		List<Map> diyahouseimf = smloadMapper.diyahouseimf(uid, houseapplyid, houseowner);
		return diyahouseimf;
	}

	@Override
	public int updateuser(int id, Double money) {
		int updateuser = smloadMapper.updateuser(id, money);
		return updateuser;
	}

	@Override
	public int updateuserlimit(int id, Double money) {
		int updateuserlimit = smloadMapper.updateuserlimit(id, money);
		return updateuserlimit;
	}


}
